clear all

********************************************************************************
********************************************************************************
**** When Can We Trust Regression Discontinuity Design Estimates from Close ****
*************** Elections? Evidence from Experimental Benchmarks ***************
********************************************************************************
********************************************************************************

* This file produces Table OA2 in Online Appendix B of De Magalhaes et al. 
* (Political Analysis).

cd "$dir"
use "$dir/data/personal_incumbency_advantage.dta", clear

********************************************************************************

* Table 1: Main results for Brazil and Denmark

est clear

eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

esttab est* using "$dir/tables/table_OA2.tex", booktabs ///
keep(Conventional Robust) nomtitles ///
mgroups("Brazil" "Denmark", pattern(1 0 0 0 1 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
replace  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Bandwidth")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead(\begin{tabular}{l*{9}{c}} \toprule) ///
postfoot("") refcat(Conventional "\textbf{Panel A:} Running t+1", nolabel)

est clear

eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(mserd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(1) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(2) all vce(cluster constituency) bwselect(cerrd) kernel(uniform)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"


esttab est* using "$dir/tables/table_OA2.tex", booktabs ///
keep(Conventional Robust) nomtitles nonumbers ///
append  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l bandwidth polynomial, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Bandwidth" "Bandwidth selector" "Polynomial")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead("") ///
postfoot(\bottomrule \end{tabular})	refcat(Conventional "\textbf{Panel B:} Elected t+1", nolabel)

est clear
